{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 随机梯度下降法(SGD)做线性拟合\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.linear_model import SGDRegressor\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\stochastic_gradient.py:84: FutureWarning: max_iter and tol parameters have been added in <class 'sklearn.linear_model.stochastic_gradient.SGDRegressor'> in 0.19. If both are left unset, they default to max_iter=5 and tol=None. If tol is not None, max_iter defaults to max_iter=1000. From 0.21, default max_iter will be 1000, and default tol will be 1e-3.\n",
      "  \"and default tol will be 1e-3.\" % type(self), FutureWarning)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x1ae9eb74c88>]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEWCAYAAABxMXBSAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJzt3Xl8VPW9//HXh0gAWWUxAkKCSiNx\nL0GMgA3ihhsVtYq1anuV1mrVWjfMbXt7bxJAUEShAooLiuJSt1J+auUaCRAUUFBIjAIGiIDsSNhC\nks/vjwzelIYhI2TOJHk/Hw8ezJk5OfOer3HenHNmvsfcHRERkZpqFHQAERGpW1QcIiISERWHiIhE\nRMUhIiIRUXGIiEhEVBwiIhIRFYfUW2b2oJk9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GiPQ0REIqLiEBGRiKg46igzu9rMlppZhZnpY4MhZnaRmRWa2TIzeyDoPLHGzJ42s/VmtiToLLHI\nzLqY2QdmVhD6/+vOoDPFIhVH3bUEGAzMCjpIrDCzOGA8MBBIAYaYWUqwqWLOs8BFQYeIYWXAH9y9\nB3AWcJt+h/6diqOOcvcCdy8MOkeMORNY5u4r3L0UmAYMCjhTTHH3WcDmoHPEKndf6+6fhG5vBwqA\nzsGmij0qDqlPOgOrqywXo//p5QcysyTgDOCjYJPEHl06NoaZ2fvAMdU8lOHub0U7Tx1g1dynz5tL\nxMysBfA34C53/y7oPLFGxRHD3P28oDPUMcVAlyrLxwJrAsoidZSZNaayNKa6++tB54lFOlQl9cl8\noLuZdTOzeOBa4O2AM0kdYmYGTAYK3P2RoPPEKhVHHWVmV5hZMZAG/MPM3g06U9DcvQy4HXiXypOa\nr7j70mBTxRYzewnIA5LNrNjM/iPoTDGmD/AL4FwzWxT6c3HQoWKNphwREZGIaI9DREQiouIQEZGI\nqDhERCQiKg4REYmIikNERCKi4hARkYioOEREJCIqDpFaZma9zOwzM2tqZs1D13k4OehcIj+UvgAo\nEgVmlgk0BZoBxe4+POBIIj+YikMkCkJzZ80HdgNnu3t5wJFEfjAdqhKJjrZAC6AllXseInWW9jhE\nosDM3qbyioTdgI7ufnvAkUR+MF2PQ6SWmdkNQJm7vxi6LvpcMzvX3f836GwiP4T2OEREJCI6xyEi\nIhFRcYiISERUHCIiEhEVh4iIRETFISIiEVFxiIhIRFQcIiISkf8PaTvW/hXk5ucAAAAASUVORK5C\nYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1ae9cb0a2e8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.title('single variable') # 图像标题\n",
    "plt.xlabel('x') # x轴文本\n",
    "plt.ylabel('y') # y轴文本\n",
    "plt.grid(True) # 是否绘制网格线\n",
    "\n",
    "x_scaler = StandardScaler()\n",
    "y_scaler = StandardScaler()\n",
    "x = [[50], [100], [150], [200], [250], [300], [50], [100], [150], [200],\n",
    "     [250], [300], [50], [100], [150], [200], [250], [300], [50], [100],\n",
    "     [150], [200], [250], [300], [50], [100], [150], [200], [250], [300],\n",
    "     [50], [100], [150], [200], [250], [300], [50], [100], [150], [200],\n",
    "     [250], [300],[50], [100], [150], [200], [250], [300]]\n",
    "y = [[150], [200], [250], [280], [310], [330], [150], [200], [250], [280],\n",
    "     [310], [330], [150], [200], [250], [280], [310], [330], [150], [200],\n",
    "     [250], [280], [310], [330], [150], [200], [250], [280], [310], [330],\n",
    "     [150], [200], [250], [280], [310], [330], [150], [200], [250], [280],\n",
    "     [310], [330], [150], [200], [260], [270], [320], [340]]\n",
    "# 标准化对每个元素进行以下操作：x' = (x - 平均值) / 标准差（注意，是标准差std，不是方差var。）\n",
    "x = x_scaler.fit_transform(x)\n",
    "y = y_scaler.fit_transform(y)\n",
    "x_test = [[40],[400]] # 用来做最终效果测试\n",
    "x_test = x_scaler.transform(x_test)\n",
    "\n",
    "plt.plot(x, y, 'k.')\n",
    "\n",
    "model = SGDRegressor()\n",
    "model.fit(x, y.ravel())\n",
    "y_result = model.predict(x_test)\n",
    "plt.plot(x_test, y_result, 'g-')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
